home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / dvips / resident.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-20  |  7.0 KB  |  293 lines

  1. /*
  2.  *   This code reads in and handles the defaults for the program from the
  3.  *   file config.sw.  This entire file is a bit kludgy, sorry.
  4.  */
  5. #include "structures.h" /* The copyright notice in that file is included too! */
  6. /*
  7.  *   This is the structure definition for resident fonts.  We use
  8.  *   a small and simple hash table to handle these.  We don't need
  9.  *   a big hash table.
  10.  */
  11. struct resfont *reshash[RESHASHPRIME] ;
  12. /*
  13.  *   These are the external routines we use.
  14.  */
  15. extern void error() ;
  16. extern integer scalewidth() ;
  17. extern void tfmload() ;
  18. extern FILE *search() ;
  19. extern shalfword pkbyte() ;
  20. extern integer pkquad() ;
  21. extern integer pktrio() ;
  22. extern Boolean pkopen() ;
  23. extern char *strcpy() ;
  24. extern char *newstring() ;
  25. extern void add_header() ;
  26. /*
  27.  *   These are the external variables we use.
  28.  */
  29. #ifdef DEBUG
  30. extern integer debug_flag;
  31. #endif  /* DEBUG */
  32. extern long bytesleft ;
  33. extern quarterword *raster ;
  34. extern FILE *pkfile ;
  35. extern char *oname ;
  36. extern integer swmem ;
  37. extern char *tfmpath ;
  38. extern char *pkpath ;
  39. extern char *vfpath ;
  40. extern char *figpath ;
  41. extern char *nextstring ;
  42. extern char *maxstring ;
  43. extern Boolean disablecomments ;
  44. extern Boolean compressed ;
  45. extern int quiet ;
  46. extern int filter ;
  47. extern Boolean reverse ;
  48. extern Boolean usesPSfonts ;
  49. extern int actualdpi ;
  50. extern int maxdrift ;
  51. extern char *printer ;
  52. extern char *mfmode ;
  53. /*
  54.  *   We use malloc here.
  55.  */
  56. char *malloc() ;
  57. /*
  58.  *   Our hash routine.
  59.  */
  60. int
  61. hash(s)
  62.    char *s ;
  63. {
  64.    int h = 12 ;
  65.  
  66.    while (*s != 0)
  67.       h = (h + h + *s++) % RESHASHPRIME ;
  68.    return(h) ;
  69. }
  70.  
  71. /*
  72.  *   The routine that looks up a font name.
  73.  */
  74. struct resfont *
  75. lookup(name)
  76.    char *name ;
  77. {
  78.    struct resfont *p ;
  79.  
  80.    for (p=reshash[hash(name)]; p!=NULL; p=p->next)
  81.       if (strcmp(p->PSname, name)==0)
  82.          return(p) ;
  83.    return(NULL) ;
  84. }
  85. /*
  86.  *   This routine adds an entry.
  87.  */
  88. void
  89. add_entry(PSname, specinfo)
  90.    char *PSname, *specinfo ;
  91. {
  92.    struct resfont *p ;
  93.    int h ;
  94.  
  95.    p = (struct resfont *)malloc((unsigned int)sizeof(struct resfont)) ;
  96.    if (p==NULL)
  97.       error("! out of memory") ;
  98.    p->PSname = PSname ;
  99.    p->specialinstructions = specinfo ;
  100.    h = hash(PSname) ;
  101.    p->next = reshash[h] ;
  102.    reshash[h] = p ;
  103. }
  104. /*
  105.  *   Now our residentfont routine.
  106.  */
  107. Boolean
  108. residentfont(curfnt)
  109.         register fontdesctype *curfnt ;
  110. {
  111.    register shalfword i ;
  112.    struct resfont *p ;
  113.  
  114. /*
  115.  *   First we determine if we can find this font in the resident list.
  116.  */
  117.    if (*curfnt->area)
  118.       return 0 ; /* resident fonts never have a nonstandard font area */
  119.    if ((p=lookup(curfnt->name))==NULL)
  120.       return 0 ;
  121. /*
  122.  *   We clear out some pointers:
  123.  */
  124. #ifdef DEBUG
  125.    if (dd(D_FONTS))
  126.         (void)fprintf(stderr,"Font %s is resident.\n", curfnt->name) ;
  127. #endif  /* DEBUG */
  128.    curfnt->resfont = p ;
  129.    for (i=0; i<256; i++) {
  130.       curfnt->chardesc[i].TFMwidth = 0 ;
  131.       curfnt->chardesc[i].packptr = NULL ;
  132.       curfnt->chardesc[i].pixelwidth = 0 ;
  133.       curfnt->chardesc[i].flags = 0 ;
  134.    }
  135.    tfmload(curfnt) ;
  136.    usesPSfonts = 1 ;
  137.    return(1) ;
  138. }
  139. static char was_inline[100] ;
  140. void
  141. bad_config() {
  142.    error("Error in config file:") ;
  143.    (void)fprintf(stderr, was_inline) ;
  144.    exit(1) ;
  145. }
  146. /*
  147.  *   Now we have the getdefaults routine.
  148.  */
  149. void
  150. getdefaults(ext)
  151.    char *ext ;
  152. {
  153.    FILE *deffile ;
  154.    char PSname[100] ;
  155.    register char *p ;
  156.    char *specinfo, *fontname ;
  157.  
  158.    strcpy(PSname, "config.") ;
  159.    strcat(PSname, ext) ;
  160.  
  161.    if ((deffile=search(CONFIGPATH,PSname))!=NULL) {
  162.       while (fgets(was_inline, 100, deffile)!=NULL) {
  163.        switch (was_inline[0]) {
  164. case 'm' :
  165. #ifdef SHORTINT
  166.          if (sscanf(was_inline+1, "%ld", &swmem) != 1) bad_config() ;
  167. #else   /* ~SHORTINT */
  168.          if (sscanf(was_inline+1, "%d", &swmem) != 1) bad_config() ;
  169. #endif  /* ~SHORTINT */
  170.          break ;
  171. case 'M' :
  172.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  173.          mfmode = newstring(PSname) ;
  174.          break ;
  175. case 'o' : case 'O' :
  176.          p = was_inline + 1 ;
  177.          while (*p && *p <= ' ')
  178.             p++ ;
  179.      /* insert printer name */
  180.      if(strchr(p, '$')) {
  181.         char buf[200];
  182.         char *dollar = strchr(p, '$');
  183.         strncpy(buf, p, dollar-p); buf[dollar-p] = '\0';
  184.         if(printer != NULL)
  185.            strcat(buf, printer);
  186.         strcat(buf, dollar+1);
  187.         oname = newstring(buf);
  188.      } else {
  189.         oname = newstring(p);
  190.      }
  191.          break ;
  192. case 't' : case 'T' :
  193.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  194.          else tfmpath = newstring(PSname) ;
  195.          break ;
  196. case 'p' : case 'P' :
  197.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  198.          else pkpath = newstring(PSname) ;
  199.          break ;
  200. case 'v' : case 'V' :
  201.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  202.          else vfpath = newstring(PSname) ;
  203.          break ;
  204. case 's' : case 'S' :
  205.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  206.          else figpath = newstring(PSname) ;
  207.          break ;
  208. case ' ' : case '*' : case '#' : case ';' : case '=' : case 0 : case '\n' :
  209.          break ;
  210. case 'r' : case 'R' :
  211.          reverse = 1 ;
  212.          break ;
  213. case 'D' :
  214.          if (sscanf(was_inline+1, "%d", &actualdpi) != 1) bad_config() ;
  215.          if (actualdpi < 10 || actualdpi > 10000) bad_config() ;
  216.          break ;
  217. case 'e' :
  218.          if (sscanf(was_inline+1, "%d", &maxdrift) != 1) bad_config() ;
  219.          if (maxdrift < 0) bad_config() ;
  220.          break ;
  221. case 'q' : case 'Q' :
  222.          quiet = 1 ;
  223.          break ;
  224. case 'f' : case 'F' :
  225.          filter = 1 ;
  226.          break ;
  227. case 'h' : case 'H' :
  228.          if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
  229.          else add_header(PSname) ;
  230.          break ;
  231. case 'N' :
  232.          disablecomments = 1 ;
  233.          break ;
  234. case 'Z' :
  235.          compressed = 1 ;
  236.          break ;
  237. default:
  238.          bad_config() ;
  239.       }
  240.      }
  241.      (void)fclose(deffile) ;
  242.      if (printer)
  243.         return ;
  244.    }
  245.    if ((deffile=search(CONFIGPATH,PSMAPFILE))!=NULL) {
  246.      while (fgets(was_inline, 100, deffile)!=NULL) {
  247.          specinfo = NULL ;
  248.          fontname = NULL ;
  249.          p = was_inline ;
  250.          while (*p && *p <= ' ')
  251.             p++ ;
  252.          if (*p) fontname = p ;
  253.          while (*p > ' ')
  254.             p++ ;
  255.          if (*p)
  256.             *p++ = 0 ;
  257.          while (*p && *p <= ' ')
  258.             p++ ;
  259.          if (*p != '"' && *p) {
  260.             while (*p > ' ')
  261.                p++ ;
  262.             if (*p)
  263.                *p++ = 0 ;
  264.             while (*p && *p <= ' ')
  265.                p++ ;
  266.          }
  267.          if (*p == '"') {
  268.             p++ ;
  269.             specinfo = p ;
  270.             while (*p && *p != '"')
  271.                p++ ;
  272.             *p = 0 ;
  273.          }
  274.          add_entry(newstring(fontname), newstring(specinfo)) ;
  275.        }
  276.        (void)fclose(deffile) ;
  277.    }
  278.    checkenv() ;
  279. }
  280. /*
  281.  *   Get environment variables! These override entries in ./config.h.
  282.  */
  283. checkenv() {
  284.    char *p, *getenv() ;
  285.  
  286.    if (p=getenv("TEXFONTS"))
  287.       tfmpath = newstring(p) ;
  288.    if (p=getenv("TEXPKS"))
  289.       pkpath = newstring(p) ;
  290.    if (p=getenv("TEXINPUTS"))
  291.       figpath = newstring(p) ;
  292. }
  293.